//
//  RingAssetDetailVC.m
//  ZZLC
//
//  Created by 杨春至 on 2018/1/3.
//  Copyright © 2018年 ZhongZeng. All rights reserved.
//

#import "RingAssetDetailVC.h"
#import "AssetRingView.h"
#import "CountModel.h"

@interface ShowLb:UIView

@property (nonatomic,strong) UILabel *countLb;

@property (nonatomic,strong) UILabel *deslb;

@property (nonatomic,strong) UIView *dotView;

- (instancetype)initWithColor:(UIColor *)color andDetsStr:(NSString *)desStr;

@end


@implementation ShowLb
- (instancetype)initWithColor:(UIColor *)color andDetsStr:(NSString *)desStr{
    if ([super init]) {
        self.countLb = [UILabel new];
        self.deslb = [UILabel new];
        self.dotView = [UIView new];
        self.deslb.text = desStr;
        self.dotView.backgroundColor = color;
        self.dotView.clipsToBounds = YES;
        self.dotView.layer.cornerRadius = 6/2;
        [self addSubview:self.countLb];
        [self addSubview:self.deslb];
        [self addSubview:self.dotView];
        self.deslb.font = [UIFont systemFontOfSize:12];

        self.countLb.font  = [UIFont systemFontOfSize:16];
        self.countLb.text = @"0.00";
        self.countLb.textAlignment = self.deslb.textAlignment = NSTextAlignmentCenter;
        self.countLb.textColor = RGBCOLOR(152, 152, 152);
        self.deslb.textColor = RGBCOLOR(158, 158, 158);
    }
    return self;
}
- (void)layoutSubviews{
    [_countLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.left.equalTo(self);
        make.width.equalTo(self);
        make.height.equalTo(@20);
    }];

    [_deslb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_countLb.mas_bottom);
        make.left.equalTo(_dotView.mas_right).offset(3);
        make.right.equalTo(_countLb);
        make.height.equalTo(@20);
    }];
    [_dotView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_deslb);
        make.size.mas_equalTo(CGSizeMake(6, 6));
        make.left.equalTo(self);
    }];
}
@end

@interface RingAssetDetailVC ()

@property (nonatomic,strong) AssetRingView *ringView;

@property (nonatomic,strong) UILabel *headLb;

@property (nonatomic,strong) UILabel *restMoneyLb;

@property (nonatomic,strong) UIView *lineView;

@property (nonatomic,strong) ShowLb *investingLb;

@property (nonatomic,strong) ShowLb *waitLb;

@property (nonatomic,strong) ShowLb *settleLb;

@property (nonatomic,strong) CountModel *model;
@end

@implementation RingAssetDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"资产明细";
//    [self loadData];
    [self configSubView];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self loadData];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setShadowImage:nil];
}
- (void)loadData{

    [NetWorkingManager postWithRequestUrl:@"User/showMyAccount" AndParameters:@{@"parameters":[@{@"authorization":[UserModel authorization]?[UserModel authorization]:@""} DataTOjsonStringAndAddVersion]} AndRequestBlock:^(NSDictionary *responseObject) {
//        [self configUIByData:responseObject];
        self.model = [CountModel objectWithKeyValues:responseObject[@"obj"]];
//        [self configSubView];
        [self loadDataByModel];
    } FailBlock:^(NSDictionary *errDic) {
        NSLog(@"%@",errDic);
    }ShowTips:YES];

    
}
- (void)configSubView{
    [self.view addSubview:self.ringView];
    [self.view addSubview:self.headLb];
    [self.view addSubview:self.restMoneyLb];
    [self.view addSubview:self.lineView];
    [self.view addSubview:self.investingLb];
    [self.view addSubview:self.waitLb];
    [self.view addSubview:self.settleLb];

}
- (void)loadDataByModel{
    if (_model) {
        NSString *countStr = [NSString stringWithFormat:@"%0.2f",[_model.totalMoney doubleValue]/100];
        NSMutableAttributedString *atri = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"资金总额(元)\n%@",countStr]];
        [atri addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0, @"资金总额(元)".length)]; //资产总额
        _headLb.attributedText = atri;
        _restMoneyLb.text = [NSString stringWithFormat:@"%0.2f",[_model.leftMoney doubleValue]/100]; //账户余额
        _investingLb.countLb.text = [NSString stringWithFormat:@"%0.2f",[_model.freezeMoney doubleValue]/100];//投资中金额
        _waitLb.countLb.text = [NSString stringWithFormat:@"%0.2f",[_model.wfsy doubleValue]/100];//待结算收益
        _settleLb.countLb.text =  [NSString stringWithFormat:@"%0.2f",[_model.totalProfit doubleValue]/100];//已经结算收益
        _ringView.dataSource = @[_investingLb.countLb.text,_waitLb.countLb.text,_settleLb.countLb.text];
    }
}
- (void)viewDidLayoutSubviews{
    CGFloat gap = 15;
    [_headLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view);
        make.height.equalTo(@140);
        make.width.equalTo(self.view);
    }];
    [_restMoneyLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(gap));
        make.right.equalTo(self.view.mas_right).offset(-gap);
        make.top.equalTo(_headLb.mas_bottom);
        make.height.equalTo(@(60));
    }];
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.top.equalTo(_restMoneyLb.mas_bottom);
        make.height.equalTo(@(0.5));
    }];
    [_investingLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_restMoneyLb);
        make.width.equalTo(@(KWidth/3-2*gap/3));
        make.height.equalTo(@50);
        make.bottom.equalTo(self.view.mas_bottom).offset(-2*gap);
    }];
    [_waitLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.width.equalTo(@(KWidth/3-2*gap/3));
        make.height.equalTo(@50);
        make.bottom.equalTo(self.view.mas_bottom).offset(-2*gap);
    }];
    [_settleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_restMoneyLb);
        make.width.equalTo(@(KWidth/3-2*gap/3));
        make.height.equalTo(@50);
        make.bottom.equalTo(self.view.mas_bottom).offset(-2*gap);
    }];
}


- (AssetRingView *)ringView{
    if (!_ringView) {
        _ringView = [[AssetRingView alloc]initWithFrame:CGRectMake(0, 201-40, KWidth, KHeight - 200-64)];
        _ringView.backgroundColor = [UIColor yellowColor];
    }
    return _ringView;
}
- (UILabel *)headLb{
    if (!_headLb) {
        _headLb = [[UILabel alloc]initWithFont:[UIFont systemFontOfSize:22] textColor:ZZGoldColor];
        _headLb.text = @"资金总额(元)\n\n10000.00";
        _headLb.textAlignment = NSTextAlignmentCenter;
        _headLb.numberOfLines = 0;
        _headLb.backgroundColor = RGBCOLOR(63, 66, 71);
        NSMutableAttributedString *atri = [[NSMutableAttributedString alloc]initWithString:_headLb.text];
        [atri addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0, @"资金总额(元)".length)];
        _headLb.attributedText = atri;
    }
    return _headLb;
}
- (UILabel *)restMoneyLb{
    if (!_restMoneyLb) {
        _restMoneyLb = [[UILabel alloc]initWithFont:[UIFont systemFontOfSize:14] textColor:ZZGoldColor];
        _restMoneyLb.textAlignment = NSTextAlignmentRight;
        _restMoneyLb.backgroundColor = [UIColor whiteColor];
        _restMoneyLb.text = @"0.00";
        UILabel *infoLb = [[UILabel alloc]initWithFont:_restMoneyLb.font textColor:RGBCOLOR(170, 170, 170)];
        infoLb.text = @"账户余额(元)";
        [infoLb sizeToFit];
        infoLb.height = 60;
        [_restMoneyLb addSubview:infoLb];
    }
    return _restMoneyLb;
}
- (UIView *)lineView{
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = RGBCOLOR(217, 217, 217);
    }
    return _lineView;
}
- (ShowLb *)investingLb{
    if (!_investingLb) {
        _investingLb = [[ShowLb alloc]initWithColor:RGBCOLOR(253, 205, 90) andDetsStr:@"投资中金额(元)"];
    }
    return _investingLb;
}
- (ShowLb *)waitLb{
    if (!_waitLb) {
        _waitLb = [[ShowLb alloc]initWithColor:RGBCOLOR(194, 237, 122) andDetsStr:@"待结算收益(元)"];
    }
    return _waitLb;
}
- (ShowLb *)settleLb{
    if (!_settleLb) {
        _settleLb = [[ShowLb alloc]initWithColor:RGBCOLOR(130, 207, 242) andDetsStr:@"已结算收益(元)"];
    }
    return _settleLb;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
